#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Solution
{
public:
	int maxProfit(vector<int>& prices)
	{
		/*int minprice = int(1e9);
		int maxprofit = 0;
		for (auto price : prices)
	{
		maxprofit = max(maxprofit, price - minprice);
		minprice = min(minprice, price);
		}*/
		
		int minprice = prices[0];
		int maxprofit = 0;
		for (size_t i = 0; i < prices.size(); i++)
		{
			maxprofit = max(maxprofit, prices[i] - minprice);
			minprice = min(minprice, prices[i]);
		}
		
		return maxprofit;
	}
};

int main()
{
    vector<int> p{ 7,1,5,3,6,4 };

    Solution xz;
    int n = xz.maxProfit(p);
    cout << n << endl;

	return 0;
}
